package com.vf.admin.client.controller.wechatlogin.controller;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.controller.wechatlogin.util.Code2AuthObj;
import com.vf.admin.client.controller.wechatlogin.util.HttpUtils;
import com.vf.admin.common.entity.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/11/18 15:47
 */
@RestController
@RequestMapping("/app/wxLogin")
public class WxLoginController extends ClientBaseController {



    @RequestMapping(value = "/loginWx")
    @ResponseBody
    public Result updateRealNameWeb(String jsCode,String xcc){
        if (ObjectUtil.isNotEmpty(xcc)){

            if (xcc.equals("zy")){
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("appid", "wx0275508931ef2ee3");
                params.put("js_code", jsCode);
                params.put("grant_type", "authorization_code");
                params.put("secret", "38c6cb7a055e5596dd25e07abb5b5ee5");
                try {
                    String  s = HttpUtils.executeHttpGet("https://api.weixin.qq.com/sns/jscode2session", params);

                    Code2AuthObj code2AuthObj = JSONObject.parseObject(s, Code2AuthObj.class);
                    return this.sucessJSON(code2AuthObj);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

            if (xcc.equals("lyq")){
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("appid", "wx25740a20cbabce54");
                params.put("js_code", jsCode);
                params.put("grant_type", "authorization_code");
                params.put("secret", "dbba4ff90db66860a030d3c52f1b71d5");
                try {
                    String  s = HttpUtils.executeHttpGet("https://api.weixin.qq.com/sns/jscode2session", params);

                    Code2AuthObj code2AuthObj = JSONObject.parseObject(s, Code2AuthObj.class);
                    return this.sucessJSON(code2AuthObj);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

            if (xcc.equals("aitaa")){
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("appid", "wxff095378edaf00da");
                params.put("js_code", jsCode);
                params.put("grant_type", "authorization_code");
                params.put("secret", "827bef592cc5acb1e34351ba0796b62d");
                try {
                    String  s = HttpUtils.executeHttpGet("https://api.weixin.qq.com/sns/jscode2session", params);

                    Code2AuthObj code2AuthObj = JSONObject.parseObject(s, Code2AuthObj.class);
                    return this.sucessJSON(code2AuthObj);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

            if (xcc.equals("ReTuu")){
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("appid", "wx035a601976c258cc");
                params.put("js_code", jsCode);
                params.put("grant_type", "authorization_code");
                params.put("secret", "0f7e4c37a464f20ca922c90906174772");
                try {
                    String  s = HttpUtils.executeHttpGet("https://api.weixin.qq.com/sns/jscode2session", params);

                    Code2AuthObj code2AuthObj = JSONObject.parseObject(s, Code2AuthObj.class);
                    return this.sucessJSON(code2AuthObj);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

            if (xcc.equals("MoTuis")){
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("appid", "wx6997d3daff9adfd0");
                params.put("js_code", jsCode);
                params.put("grant_type", "authorization_code");
                params.put("secret", "12ca27820273f5e5ae8fd5e7b1b45672");
                try {
                    String  s = HttpUtils.executeHttpGet("https://api.weixin.qq.com/sns/jscode2session", params);

                    Code2AuthObj code2AuthObj = JSONObject.parseObject(s, Code2AuthObj.class);
                    return this.sucessJSON(code2AuthObj);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            if (xcc.equals("ReTus")){
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("appid", "wx90c0d560b2c7b0c0");
                params.put("js_code", jsCode);
                params.put("grant_type", "authorization_code");
                params.put("secret", "4c8b190b661aa84e4c3287956889503f");
                try {
                    String  s = HttpUtils.executeHttpGet("https://api.weixin.qq.com/sns/jscode2session", params);

                    Code2AuthObj code2AuthObj = JSONObject.parseObject(s, Code2AuthObj.class);
                    return this.sucessJSON(code2AuthObj);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            if (xcc.equals("AITAS")){
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("appid", "wx5f49a645c7d0e471");
                params.put("js_code", jsCode);
                params.put("grant_type", "authorization_code");
                params.put("secret", "bc846c0ca08aeb5247f2f9ecc9308dc9");
                try {
                    String  s = HttpUtils.executeHttpGet("https://api.weixin.qq.com/sns/jscode2session", params);

                    Code2AuthObj code2AuthObj = JSONObject.parseObject(s, Code2AuthObj.class);
                    return this.sucessJSON(code2AuthObj);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            if (xcc.equals("MoTui")){
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("appid", "wxb20068a866d2f394");
                params.put("js_code", jsCode);
                params.put("grant_type", "authorization_code");
                params.put("secret", "15788559bcd79e760b5f3245cab52f9e");
                try {
                    String  s = HttpUtils.executeHttpGet("https://api.weixin.qq.com/sns/jscode2session", params);

                    Code2AuthObj code2AuthObj = JSONObject.parseObject(s, Code2AuthObj.class);
                    return this.sucessJSON(code2AuthObj);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }

        }






        return this.sucessJSON("参数错误");
    }

}
